home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / pippki.jar / content / pippki / pref-crlupdate.js < prev    next >
Encoding:
Text File  |  2006-07-13  |  9.0 KB  |  269 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Rangan Sen <rangansen@netscape.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const nsICRLManager = Components.interfaces.nsICRLManager;
  39. const nsCRLManager  = "@mozilla.org/security/crlmanager;1";
  40. const nsIPKIParamBlock    = Components.interfaces.nsIPKIParamBlock;
  41. const nsICRLInfo          = Components.interfaces.nsICRLInfo;
  42. const nsIPrefService      = Components.interfaces.nsIPrefService;
  43.  
  44. var crl;
  45. var bundle;
  46. var prefService;
  47. var prefBranch;
  48. var updateTypeRadio;
  49. var enabledCheckBox;
  50. var timeBasedRadio;
  51. var freqBasedRadio;
  52. var crlManager;
  53.  
  54. var autoupdateEnabledString   = "security.crl.autoupdate.enable.";
  55. var autoupdateTimeTypeString  = "security.crl.autoupdate.timingType.";
  56. var autoupdateTimeString      = "security.crl.autoupdate.nextInstant.";
  57. var autoupdateURLString       = "security.crl.autoupdate.url.";
  58. var autoupdateErrCntString    = "security.crl.autoupdate.errCount.";
  59. var autoupdateErrDetailString = "security.crl.autoupdate.errDetail.";
  60. var autoupdateDayCntString    = "security.crl.autoupdate.dayCnt.";
  61. var autoupdateFreqCntString   = "security.crl.autoupdate.freqCnt.";
  62.  
  63. function onLoad()
  64. {
  65.   crlManager = Components.classes[nsCRLManager].getService(nsICRLManager);
  66.   var pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);  
  67.   var isupport = pkiParams.getISupportAtIndex(1);
  68.   crl = isupport.QueryInterface(nsICRLInfo);
  69.  
  70.   autoupdateEnabledString    = autoupdateEnabledString + crl.nameInDb;
  71.   autoupdateTimeTypeString  = autoupdateTimeTypeString + crl.nameInDb;
  72.   autoupdateTimeString      = autoupdateTimeString + crl.nameInDb;
  73.   autoupdateDayCntString    = autoupdateDayCntString + crl.nameInDb;
  74.   autoupdateFreqCntString   = autoupdateFreqCntString + crl.nameInDb;
  75.   autoupdateURLString       = autoupdateURLString + crl.nameInDb;
  76.   autoupdateErrCntString    = autoupdateErrCntString + crl.nameInDb;
  77.   autoupdateErrDetailString = autoupdateErrDetailString + crl.nameInDb;
  78.  
  79.   bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  80.   prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(nsIPrefService);
  81.   prefBranch = prefService.getBranch(null);
  82.  
  83.   updateTypeRadio = document.getElementById("autoUpdateType");
  84.   enabledCheckBox = document.getElementById("enableCheckBox");
  85.   timeBasedRadio = document.getElementById("timeBasedRadio");
  86.   freqBasedRadio = document.getElementById("freqBasedRadio");
  87.  
  88.   //Read the existing prefs, if any
  89.   initializeSelection();
  90. }
  91.  
  92. function updateSelectedTimingControls()
  93. {
  94.   var freqBox = document.getElementById("nextUpdateFreq");
  95.   var timeBox = document.getElementById("nextUpdateDay");
  96.   if(updateTypeRadio.selectedItem.id == "freqBasedRadio"){
  97.     freqBox.removeAttribute("disabled");
  98.     timeBox.disabled = true;
  99.   } else {
  100.     timeBox.removeAttribute("disabled");
  101.     freqBox.disabled = true;
  102.   }
  103. }
  104.  
  105. function initializeSelection()
  106. {
  107.   var menuItemNode;
  108.   var hasAdvertisedURL = false;
  109.   var hasNextUpdate = true;
  110.  
  111.   var lastFetchMenuNode;
  112.   var advertisedMenuNode;
  113.   
  114.   try {
  115.     var isEnabled = prefBranch.getBoolPref(autoupdateEnabledString);
  116.     enabledCheckBox.checked = isEnabled;
  117.   } catch(exception){
  118.     enabledCheckBox.checked = false;
  119.   }
  120.  
  121.   //Always the last fetch url, for now.
  122.   var URLDisplayed = document.getElementById("urlName"); 
  123.   URLDisplayed.value = crl.lastFetchURL;
  124.   
  125.   //Decide how many update timing types to be shown
  126.   //If no next update specified, hide the first choice. Default shows both
  127.   if(crl.nextUpdateLocale == null || crl.nextUpdateLocale.length == 0) {
  128.     timeBasedRadio.disabled = true;
  129.     hasNextUpdate = false;
  130.   }
  131.   
  132.   //Set up the initial selections based on defaults and prefs, if any
  133.   try{
  134.     var timingPref = prefBranch.getIntPref(autoupdateTimeTypeString);
  135.     if(timingPref != null) {
  136.       if(timingPref == crlManager.TYPE_AUTOUPDATE_TIME_BASED) {
  137.         if(hasNextUpdate){
  138.           updateTypeRadio.selectedItem = timeBasedRadio;
  139.         }
  140.       } else {
  141.         updateTypeRadio.selectedItem = freqBasedRadio;
  142.       }
  143.     } else {
  144.       if(hasNextUpdate){
  145.         updateTypeRadio.selectedItem = timeBasedRadio;
  146.       } else {
  147.         updateTypeRadio.selectedItem = freqBasedRadio;
  148.       }
  149.     }
  150.     
  151.   }catch(exception){
  152.     if(!hasNextUpdate) {
  153.       updateTypeRadio.selectedItem = freqBasedRadio;
  154.     } else {
  155.       updateTypeRadio.selectedItem = timeBasedRadio;
  156.     }
  157.   }
  158.  
  159.   updateSelectedTimingControls();
  160.  
  161.   //Now, retrieving the day count
  162.   var timeBasedBox = document.getElementById("nextUpdateDay");
  163.   try {
  164.     var dayCnt = prefBranch.getCharPref(autoupdateDayCntString);
  165.     //alert(dayCnt);
  166.     if(dayCnt != null){
  167.       timeBasedBox.value = dayCnt;
  168.     } else {
  169.       timeBasedBox.value = 1; 
  170.     }
  171.   } catch(exception) {
  172.     timeBasedBox.value = 1;
  173.   }
  174.  
  175.   var freqBasedBox = document.getElementById("nextUpdateFreq");
  176.   try {
  177.     var freqCnt = prefBranch.getCharPref(autoupdateFreqCntString);
  178.     //alert(freqCnt);
  179.     if(freqCnt != null){
  180.       freqBasedBox.value = freqCnt;
  181.     } else {
  182.       freqBasedBox.value = 1; 
  183.     }
  184.   } catch(exception) {
  185.     freqBasedBox.value = 1;
  186.   }
  187.  
  188.   var errorCountText = document.getElementById("FailureCnt");
  189.   var errorDetailsText = document.getElementById("FailureDetails");
  190.   var cnt = 0;
  191.   var text;
  192.   try{
  193.     cnt = prefBranch.getIntPref(autoupdateErrCntString);
  194.     txt = prefBranch.getCharPref(autoupdateErrDetailString);
  195.   }catch(exception){}
  196.  
  197.   if( cnt > 0 ){
  198.     errorCountText.setAttribute("value",cnt);
  199.     errorDetailsText.setAttribute("value",txt);
  200.   } else {
  201.     errorCountText.setAttribute("value",bundle.GetStringFromName("NoUpdateFailure"));
  202.     var reasonBox = document.getElementById("reasonbox");
  203.     reasonBox.hidden = true;
  204.   }
  205. }
  206.  
  207. function onCancel()
  208. {
  209.   // Close dialog by returning true
  210.   return true;
  211. }
  212.  
  213. function onAccept()
  214. {
  215.    if(!validatePrefs())
  216.      return false;
  217.  
  218.    //set enable pref
  219.    prefBranch.setBoolPref(autoupdateEnabledString, enabledCheckBox.checked );
  220.    
  221.    //set URL TYPE and value prefs - always to last fetch url - till we have anything else available
  222.    prefBranch.setCharPref(autoupdateURLString, crl.lastFetchURL);
  223.    
  224.    var timingTypeId = updateTypeRadio.selectedItem.id;
  225.    var updateTime;
  226.    var dayCnt = (document.getElementById("nextUpdateDay")).value;
  227.    var freqCnt = (document.getElementById("nextUpdateFreq")).value;
  228.  
  229.    if(timingTypeId == "timeBasedRadio"){
  230.      prefBranch.setIntPref(autoupdateTimeTypeString, crlManager.TYPE_AUTOUPDATE_TIME_BASED);
  231.      updateTime = crlManager.computeNextAutoUpdateTime(crl, crlManager.TYPE_AUTOUPDATE_TIME_BASED, dayCnt);
  232.    } else {
  233.      prefBranch.setIntPref(autoupdateTimeTypeString, crlManager.TYPE_AUTOUPDATE_FREQ_BASED);
  234.      updateTime = crlManager.computeNextAutoUpdateTime(crl, crlManager.TYPE_AUTOUPDATE_FREQ_BASED, freqCnt);
  235.    }
  236.  
  237.    //alert(updateTime);
  238.    prefBranch.setCharPref(autoupdateTimeString, updateTime); 
  239.    prefBranch.setCharPref(autoupdateDayCntString, dayCnt);
  240.    prefBranch.setCharPref(autoupdateFreqCntString, freqCnt);
  241.  
  242.    //Save Now
  243.    prefService.savePrefFile(null);
  244.    
  245.    crlManager.rescheduleCRLAutoUpdate();
  246.    //Close dialog by returning true
  247.    return true;
  248. }
  249.  
  250. function validatePrefs()
  251. {
  252.    var dayCnt = (document.getElementById("nextUpdateDay")).value;
  253.    var freqCnt = (document.getElementById("nextUpdateFreq")).value;
  254.  
  255.    var tmp = parseFloat(dayCnt);
  256.    if(!(tmp > 0.0)){
  257.      alert(bundle.GetStringFromName("crlAutoUpdateDayCntError"));
  258.      return false;
  259.    }
  260.    
  261.    tmp = parseFloat(freqCnt);
  262.    if(!(tmp > 0.0)){
  263.      alert(bundle.GetStringFromName("crlAutoUpdtaeFreqCntError"));
  264.      return false;
  265.    }
  266.    
  267.    return true;
  268. }
  269.